﻿using UnityEngine;
using System.Collections;

public class TimedEvent : MonoBehaviour {

    float m_fSpeed;

    public string strEventID;

    bool m_bSetTimerOnce;
    bool m_bEventingOnce;

	// Use this for initialization
	void Start () {
        if (Clock.iHour >= 1 && Clock.iHour <= 14)
        {
            GetComponent<UISprite>().color = new Color(29 / 255f, 26 / 255f, 24 / 255f);
        }
        else
        {
            GetComponent<UISprite>().color = new Color(189 / 255f, 173 / 255f, 160 / 255f);
        }
        GetComponent<UISprite>().spriteName = "TimedEvent";
        //switch ((intstrEventID)
        //{
        //    case 0:
        //        GetComponent<UISprite>().spriteName = "TimedEvent";
        //        break;
        //}
        transform.localScale = new Vector3(0.1f, 0.1f);
	}
	
	// Update is called once per frame
	void Update () {
        m_fSpeed = Clock.fElapseSpeed * 1.225f;

        if (transform.localPosition.x < 0.01f && !m_bEventingOnce)
        {
            m_bEventingOnce = true;
            ResourceMgr.GetInstance().CreateEventMsg(strEventID);
        }else if (m_bEventingOnce)
        {
            EventDelegate.Add(GetComponent<TweenAlpha>().onFinished, DeleteThis);
            GetComponent<TweenAlpha>().Play(false);
            if (!m_bSetTimerOnce)
            {
                GameObject.Find("EventMgr").GetComponent<EventMgr>().SetTimedEventTimer(); // 이벤트 타이머 재시작
                m_bSetTimerOnce = true;
            }

        }
        else
        {
            transform.localPosition -= new Vector3(m_fSpeed, 0);
            GetComponent<TweenPosition>().from.x = transform.localPosition.x;
            GetComponent<TweenPosition>().to.x = transform.localPosition.x;
        }
	}

    void DeleteThis()
    {
        Destroy(gameObject);
    }
}
